package io.scnb.coupon.customer.feign.fallback;

import io.scnb.coupon.customer.feign.TemplateService;
import io.scnb.coupon.template.api.beans.CouponTemplateInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Map;

@Slf4j
@Component
public class TemplateServiceFallbackFactory implements FallbackFactory<TemplateService> {

    /**
     * 使用这种工厂方法，可以得到具体的异常cause
     * @param cause
     * @return
     */
    @Override
    public TemplateService create(Throwable cause) {
        return new TemplateService() {

            @Override
            public CouponTemplateInfo getTemplate(Long id) {
                log.info("fallback factory method test");
                return null;
            }

            @Override
            public Map<Long, CouponTemplateInfo> getTemplateInBatch(Collection<Long> ids) {
                log.info("fallback factory method test");
                return null;
            }
        }; 
    }
}
